package p6_1;

import java.util.ArrayList;
import java.util.Collection;

public class purse 
{
	//instance variables
	private ArrayList<String> purse;
	private ArrayList<String> klon = new ArrayList<String>();
	//constructors
	public purse()
	{
		purse = new ArrayList<String>();
	}
	
	//methods
	/**
	 * Adds a coin to the purse
	 * @param coinName
	 */
	public void addCoin(String coinName)
	{
		purse.add(coinName);
	}
	
	/**
	 * Returns the purse as a string.
	 */
	public String toString()
	{
		String purseString = "";
		for (String coin : purse)
		{
			purseString += coin+"\n";
		}
	return purseString;
	}
	
	/**
	 * Reverses the order of the purse.
	 */
	@SuppressWarnings("unchecked")
	public void reverse()
	{
		
		klon= (ArrayList<String>) purse.clone();
		int size = purse.size();
		for (String l: purse)
		{
			size--;
			klon.set(size, l);
		}
		purse = klon;
	}
	
	public void transfer(purse b)
	{
		purse.addAll(b.purse);
	}
	
	public void equals(purse b)
	{
		purse.equals(b.purse);
	}
	
	public boolean equalsIgnoreOrder(purse pung2)
	{
		if (purse.size()==pung2.purse.size())
		{
			int match = 0;
			for (String a: purse)
			{
				for (String b: pung2.purse)
				{
					if (a.equals(b))
					{
						match++;
						break;
					}
				}
			}
			if (match == purse.size())
			{
				return true;
			}
			return false;
		}
		
		return false;
	}
	

}
